package org.xxmi.oop.model;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;

/**
 * Created by XXMI-CY on 2017/8/3.
 */
public class MyThread {
//    public static void main(String[] args) {
//
//        ArrayList arrayList = new ArrayList();
//        arrayList.add(1);
//        arrayList.add(1.234);
//        arrayList.add('a');
//        arrayList.add(true);
//        arrayList.add("ArrayList");
//        System.out.println(arrayList);
//
//        String arr[] = new String[]{"a","b"};
//
//    }

    static final int N=50000;
    static long timeList(List list){
        long start=System.currentTimeMillis();
        Object o = new Object();
        for(int i=0;i<N;i++) {
            list.add(0, o);
        }
        return System.currentTimeMillis()-start;
    }
    static long readList(List list){
        long start=System.currentTimeMillis();
        for(int i=0,j=list.size();i<j;i++){

        }
        return System.currentTimeMillis()-start;
    }

    static List addList(List list){
        Object o = new Object();
        for(int i=0;i<N;i++) {
            list.add(0, o);
        }
        return list;
    }
    public static void main(String[] args) {
        System.out.println("ArrayList添加"+N+"条耗时："+timeList(new ArrayList()));
        System.out.println("LinkedList添加"+N+"条耗时："+timeList(new LinkedList()));

        List list1=addList(new ArrayList());
        List list2=addList(new LinkedList());
        System.out.println("ArrayList查找"+N+"条耗时："+readList(list1));
        System.out.println("LinkedList查找"+N+"条耗时："+timeList(list2));
    }
}
